#ifndef CHESSBOARD_H
#define CHESSBOARD_H

#include <QWidget>
#include<QPainter>
#include<QMouseEvent>
#include<QVector>
#include<QMessageBox>
#include"chess.h"
enum ChessType{
    White,
    Black
};

#define Board_Rows_Cols 15 //棋盘14×14个格子
#define Board_Cell_WH  50 //每个格子的宽高
#define Board_Offset_Window 25  //棋盘相较于窗口的偏移量


namespace Ui {
class ChessBoard;
}

class ChessBoard : public QWidget
{
    Q_OBJECT

public:
    explicit ChessBoard(QWidget *parent = nullptr);
    ~ChessBoard();
    int detectionChess(Chess chess,QPoint pos);    //检测棋子周围的连珠数量
    inline void setChessColor(int color){ChessColor = color;update();}
    inline int getChessColor(){return ChessColor;}
signals:
    void signal_timerChange();//此信号表示一方落子,计时器交换
    void signal_gameover(); //此信号表示游戏结束,需开始下一轮游戏
    void signal_clearBoard();//此信号表示用户返回菜单界面,重新选择模式,棋盘需要清空
    void signal_whiteTimeout(); //此信号表示白棋倒计时结束
    void signal_blackTimeout(); //此信号表示黑棋倒计时结束
    void signal_GameMode(int type); //此信号传递用户选择的模式
    void signal_chesspos(int color,QPoint pos);     //此信号传递己方落子信息
    void signal_recevePeerChess(int color,QPoint pos);   //此信号接收对方落子信息
    void signal_win(int color);     //发送某一方胜利消息
    void signal_receveWin(int color);   //接收某一方胜利消息
protected:
    void paintEvent(QPaintEvent* evnet);
    void mousePressEvent(QMouseEvent* ev);
private:
    Ui::ChessBoard *ui;
    int ChessColor = White; //棋子颜色
    QVector<Chess> vec;    //维护落下的棋子
    int gamemode;   //当前用户选择的模式
};

#endif // CHESSBOARD_H
